/**
 * 浏览统计管理初始化
 */
var LogClickCount = {
    id: "LogClickCountTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
LogClickCount.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '编号', field: 'typeCode', visible: true, align: 'center', valign: 'middle'},
            {title: '类型', field: 'typeName', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'valueName', visible: true, align: 'center', valign: 'middle'},
            {title: '点击次数', field: 'counts', visible: true, align: 'center', valign: 'middle'},

    ];
};

/**
 * 检查是否选中
 */
LogClickCount.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        LogClickCount.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加浏览统计
 */
LogClickCount.openAddLogClickCount = function () {
    var index = layer.open({
        type: 2,
        title: '添加浏览统计',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/logClickCount/logClickCount_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看浏览统计详情
 */
LogClickCount.openLogClickCountDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '浏览统计详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/logClickCount/logClickCount_update/' + LogClickCount.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除浏览统计
 */
LogClickCount.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/logClickCount/delete", function (data) {
            Feng.success("删除成功!");
            LogClickCount.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("logClickCountId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询浏览统计列表
 */
LogClickCount.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['typeCode'] = $("#typeCode").val();
    LogClickCount.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = LogClickCount.initColumn();
    var table = new BSTable(LogClickCount.id, "/logClickCount/list", defaultColunms);
    table.setPaginationType("client");
    LogClickCount.table = table.init();
});


LogClickCount.resetSearch = function () {
    $("#name").val("");
    $("#beginTime").val("");
    $("#endTime").val("");

    LogClickCount.search();
}
